"""
wrapper to run the bayes classifer
"""
from LyricEmotion.pyweka.arff import *

class RunWekaError(Exception): pass
class TrainFileNotExistError(RunWekaError):pass
class TestFileNotExistError(RunWekaError):pass
class EssentialParamNotExistError(RunWekaError):pass

def NBDetail(params):
    """
    @param the trainfile and testfile -t -T >
    # user define 
    -t classtrain.arff
    -T classtest.arff
    > smodisclassresult.txt

    # get from the arff file
    -p should get here

    # default
    -i
    -distribution
    """
    cmd = "java weka.classifiers.bayes.NaiveBayes "
    defaultparams = {"-i":"","-distribution":""}

    if (not params.has_key("-t")) or (not params.has_key("-T")) or (not params.has_key(">")):
        raise EssentialParamNotExistError("params not exist error")

    attrs = getAttrList(params["-t"])
    params["-p"] = str(len(attrs))

    for key in defaultparams:
        cmd += " "+key+" "+defaultparams[key]
    
    for key in params:
        if key == ">":
            continue
        cmd += " "+key+" "+params[key]
    cmd += " > "+params[">"]
    
    os.system(cmd)


def NBNoDetailNoTest(params):
    """
    @param the trainfile and testfile -t -T >
    # user define 
    -t classtrain.arff
    > smodisclassresult.txt

    # default
    -i
    """
    cmd = "java weka.classifiers.bayes.NaiveBayes "
    defaultparams = {"-i":"","-x":"5"}

    if (not params.has_key("-t")) or (not params.has_key(">")):
        raise EssentialParamNotExistError("params not exist error")

    for key in defaultparams:
        cmd += " "+key+" "+defaultparams[key]
    
    for key in params:
        if key == ">":
            continue
        cmd += " "+key+" "+params[key]
    cmd += " > "+params[">"]
    
    os.system(cmd)
